
#import "HelpViewController.h"
#import "CustomNavigationBar.h"
#import "UINavigationItem+Customization.h"
#import "NSString+VoiceOver.h"

@interface HelpViewController ()

@end

@implementation HelpViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg.png"]];
    
    NSString *locale = @"sv";
    NSString *file = [locale stringByAppendingFormat:@"_%@", self.documentFile];
    NSString *html = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] 
                                                         pathForResource:file
                                                         ofType:@"html"] 
                                               encoding:NSUTF8StringEncoding error:nil];
    html = [html stringByReplacingOccurrencesOfString:@"../" withString:@""];
    if (voiceoverEnabled) {
        html = [html stringByOptimizingForVoiceOver];
    }
    NSString *path = [[NSBundle mainBundle] bundlePath];
    NSURL *baseURL = [NSURL fileURLWithPath:path];
    self.webView.dataDetectorTypes = UIDataDetectorTypeNone;
    [self.webView loadHTMLString:html baseURL:baseURL];
    
    UINavigationItem *item = self.navigationBar.items[0];
    item.title = self.title;
    [self.navigationBar applyDefaultStyle];
    
    UIButton *doneButton = [self.navigationBar doneButtonWith:[UIImage imageNamed:@"btn-resultat-klar-off.png"] highlight:[UIImage imageNamed:@"btn-resultat-klar-on.png"] leftCapWidth:14.0 title:_(@"Klar")];
    [doneButton addTarget:self action:@selector(donePressed) forControlEvents:UIControlEventTouchUpInside];
    item.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:doneButton];
    
    [item customizeTitleInNavigationBarWithHeight:self.navigationBar.frame.size.height];
}

- (void)viewDidUnload
{
    [self setWebView:nil];
    [self setNavigationBar:nil];
    [super viewDidUnload];
}

- (void)donePressed
{
    [self dismissModalViewControllerAnimated:YES];
}

@end
